<template>
  <vxe-modal title="研发活动证明(村料消耗)选择" v-model="dialogVisible" width="80%" append-to-body showFooter esc-closable show-zoom resize>
    <div style="height: 75vh; overflow-y: auto;">
      <!-- 顶部搜索 -->
      <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="100px">
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item label="年度:" prop="nd">
              <el-input
                v-model="queryParams.nd"
                placeholder="请输入年度"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目名称:" prop="xmName">
              <el-input
                v-model="queryParams.xmName"
                placeholder="请输入项目名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目编号:" prop="xmBh">
              <el-input
                v-model="queryParams.xmBh"
                placeholder="请输入项目编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- 表格 -->
      <el-table @row-click="clickRow" ref="table" highlight-current-row height="300"
                :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                class="fixedTableTwo" v-loading="loading" :data="clxhtbList">
        <!--      <el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
        <el-table-column label="年度" align="center" prop="nd" width="60"/>
        <el-table-column label="项目名称" align="center" prop="xmName">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleButtonClick(scope.row)"
            >
              <el-link type="primary">{{ '(第' + scope.row.jlCs + '次)' + scope.row.xmName }}</el-link>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="项目编号" align="center" prop="xmBh"/>
        <el-table-column show-overflow-tooltip label="申请单位" align="center" prop="sqDw"/>
        <el-table-column label="凭证关联(笔)" align="center" prop="pzglCount">
          <template slot-scope="scope">
            <span style="color: #13ce66; font-weight: 700">{{ scope.row.pzglCount }}</span>
          </template>
        </el-table-column>
      </el-table>

      <!-- 列表分页 -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <div slot="footer" class="dialog-footer dialog-footer-center">
      <el-button size="small" @click="submitForm">
        <svg-icon icon-class="confirm1" class-name='custom-class' />确 定
      </el-button>
      <el-button size="small" @click="cancel">
        <svg-icon icon-class="cancel1" class-name='custom-class' />取 消
      </el-button>
    </div>

    <!-- 材料消耗填报详情 -->
    <ClXhTbXq ref="clXhTbXq"/>
  </vxe-modal>
</template>

<script>
import {listClxhtb, selectClXhDxList} from "@/api/fztz/clxhtb";
import ClXhTbXq from "@/views/fztz/clxhtb/components/ClXhTbXq.vue";

export default {
  //材料消耗单选组件
  name: "ClXhDx",
  components: {ClXhTbXq},
  inject: ['updateClXhLabel'],
  data() {
    return {
      xmsbId: null, //从外部传过来的项目申报ID
      // 材料消耗填报表格数据
      clxhtbList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      dialogVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nd: null,
        xmsbId: null,
        xmName: null,
        xmBh: null,
        jlQTime: null,
        jlZTime: null,
        xmFzName: null,
        idWhere: null,
        userId: null,
        deptId: null
      },
      // 总条数
      total: 0,
      clXhLable: null,

    }
  },
  methods: {
    //确定按钮
    submitForm(){
      this.updateClXhLabel(this.clXhLable);
      this.dialogVisible = false;
    },
    //打开材料消耗填报详情组件
    handleButtonClick(row) {
      this.$refs.clXhTbXq.handleOpen(row)
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      this.clXhLable = this.selectedRow
      const table = this.$refs.table;
      const selectedRows = table.selection;
      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleOpen(xmsbId) {
      this.xmsbId = xmsbId
      this.dialogVisible = true
      this.getList();
    },
    cancel() {
      this.dialogVisible = false;
    },
    /** 查询材料消耗填报列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      this.queryParams.xmsbId = this.xmsbId
      selectClXhDxList(this.queryParams).then(response => {
        console.log(response.rows, 'asasdadsasdadsadsasd')
        this.clxhtbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


  }
}
</script>

<style scoped>

</style>
